/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package queenb.net.entitybean;

import java.io.Serializable;
import java.sql.SQLException;
import java.util.List;
import oracle.jdbc.OracleTypes;
import queenb.net.annotation.Mapping;
import queenb.net.datacontrol.DataControl;
import queenb.net.datacontrol.DataStatement;
import queenb.net.datacontrol.Param;
import queenb.web.util.PackageContants;
import java.sql.Types;
import java.util.logging.Level;
import queenb.web.controller.LoginCon;
import queenb.web.crm.store.K400Store;
import queenb.web.store.N450Store;
import queenb.web.util.SessionProvider;

/**
 *
 * @author thanhct
 */
public class Login extends DataControl<Login> implements Serializable {

    @Mapping(name = "pn100", typeMapping = OracleTypes.INTEGER)
    public int id;
    @Mapping(name = "nv102", typeMapping = OracleTypes.CHAR)
    public String lastName;
    @Mapping(name = "nv103", typeMapping = OracleTypes.CHAR)
    public String firstName;
    @Mapping(name = "qv101", typeMapping = OracleTypes.CHAR)
    public String userName;
    private String password;
    @Mapping(name = "ph200", typeMapping = OracleTypes.INTEGER)
    public int companyNo;
    @Mapping(name = "ni104", typeMapping = OracleTypes.INTEGER)
    public int ni104;
    @Mapping(name = "hv201", typeMapping = OracleTypes.CHAR)
    public String companyName;
    @Mapping(name = "fn550", typeMapping = OracleTypes.INTEGER)
    public int departmentNo;
    @Mapping(name = "fc5003", typeMapping = OracleTypes.INTEGER)
    public int fc5003;
    @Mapping(name = "dep", typeMapping = OracleTypes.CHAR)
    public String phongBan;
    @Mapping(name = "nv", typeMapping = OracleTypes.INTEGER)
    public int customer;// 1 is employee, 0 is customer
    @Mapping(name = "val", typeMapping = OracleTypes.INTEGER)
    private int val;
    @Mapping(name = "label", typeMapping = OracleTypes.CHAR)
    private String label;
    @Mapping(name = "qv114", typeMapping = OracleTypes.CHAR)
    private String qv114;
    @Mapping(name = "qv115", typeMapping = OracleTypes.CHAR)
    private String qv115;
    @Mapping(name = "qv116", typeMapping = OracleTypes.CHAR)
    public String qv116;
    @Mapping(name = "qv117", typeMapping = OracleTypes.CHAR)
    private String qv117;
    @Mapping(name = "qv118", typeMapping = OracleTypes.CHAR)
    private String qv118;
    @Mapping(name = "qv119", typeMapping = OracleTypes.CHAR)
    private String qv119;
    @Mapping(name = "qv120", typeMapping = OracleTypes.CHAR)
    private String qv120;
    @Mapping(name = "qv121", typeMapping = OracleTypes.CHAR)
    private String qv121;
    @Mapping(name = "status", typeMapping = OracleTypes.CHAR)
    private String status;
    @Mapping(name = "fullad", typeMapping = OracleTypes.INTEGER)
    private int fullad;
    private boolean showGlobalMessage;
    private String globalMessage = "Success! The item was saved successfully.";
    private boolean showLocalMessage;
    private String localMessage = "Success! The item was saved successfully.";
    private int module = 7;
    private String character = "A";
    private List<N450> listN450;
    private List<N850> listN850;
    @Mapping(name = "grpid", typeMapping = OracleTypes.INTEGER)
    private int fn850;
    @Mapping(name = "nv451", typeMapping = OracleTypes.CHAR)
    private String nv451;
    @Mapping(name = "nv851", typeMapping = OracleTypes.CHAR)
    private String nv851;
    @Mapping(name = "nv251", typeMapping = OracleTypes.CHAR)
    private String nv251;
    @Mapping(name = "NV115", typeMapping = OracleTypes.CHAR)
    private String nv115;
    @Mapping(name = "hoten", typeMapping = OracleTypes.CHAR)
    private String hoten;
    @Mapping(name = "dep", typeMapping = OracleTypes.INTEGER)
    private int fn450;
    @Mapping(name = "fk100", typeMapping = OracleTypes.INTEGER)
    private int fk100;
    private String sex;

    public Login() {
        System.out.println("---------vao login ------------");
    }

    public Login(String hoten, String nv251, String nv115, String nv451, String nv851, int fc5003, List<N450> listN450, List<N850> listN850, int id, String lastName, String firstName, String userName, String password, int companyNo, String companyName, int departmentNo, String phongBan, int customer, String qv114, String qv115, String qv116, String qv117, String qv118, String qv119, String qv120, String qv121) {
        this.id = id;
        this.lastName = lastName;
        this.firstName = firstName;
        this.userName = userName;
        this.password = password;
        this.companyNo = companyNo;
        this.companyName = companyName;
        this.departmentNo = departmentNo;
        this.phongBan = phongBan;
        this.customer = customer;
        this.qv114 = qv114;
        this.qv115 = qv115;
        this.qv116 = qv116;
        this.qv117 = qv117;
        this.qv118 = qv118;
        this.qv119 = qv119;
        this.qv120 = qv120;
        this.qv121 = qv121;
        this.listN450 = listN450;
        this.listN850 = listN850;
        this.fc5003 = fc5003;
        this.nv451 = nv451;
        this.nv851 = nv851;
        this.nv251 = nv251;
        this.nv115 = nv115;
        this.hoten = hoten;
    }

    public Login checkLogin(int pnFH000, String username, String pwd) throws SQLException, InstantiationException, IllegalAccessException {
        int[] returnType = {
            OracleTypes.CURSOR,
            OracleTypes.INTEGER,};

        DataStatement login = new DataStatement(PackageContants.ADMIN_TOOLS_CHECKUSERLOGIN, OracleTypes.CURSOR, new Param[]{
                    new Param(OracleTypes.CHAR, username),
                    new Param(OracleTypes.CHAR, pwd),
                    new Param(OracleTypes.INTEGER, pnFH000)
                });

        System.out.println("####pnFH000=" + pnFH000);
        System.out.println("####username=" + username);
        System.out.println("####pwd=" + pwd);
        //return update(login, Login.class);
        List<Login> l = super.find(login, Login.class);

        return l.get(0);
    }

    public List<Login> getUserInfo(String userName) throws SQLException, InstantiationException, IllegalAccessException {
//        DataStatement userInfor = new DataStatement("QCURPKS.ListOfTabQ100", OracleTypes.CURSOR, new Param[]{
        DataStatement userInfor = new DataStatement(PackageContants.QCURPKS_LISTOFTABQ100, OracleTypes.CURSOR, new Param[]{
                    new Param(OracleTypes.CHAR, userName)
                });
        System.out.println("####userName=" + userName);
        return super.find(userInfor, Login.class);
    }

//    public List<Q400> getListQ400Filter(int FN100, String kv402) throws SQLException, InstantiationException, InstantiationException {
//        K400Store k400Store = new K400Store();
//        try {
//            // listQ400 = k400Store.CombK400(7, 99, 0, getUserName());
//            List<Q400> listQ400Filter = k400Store.COMBTABK400F(7, 99, FN100, 0, kv402, getUserName());
//            SessionProvider.setSessionMapValue("listQ400Filter", listQ400Filter);
//            return listQ400Filter;
//        } catch (IllegalAccessException ex) {
//            java.util.logging.Logger.getLogger(LoginCon.class.getName()).log(Level.SEVERE, null, ex);
//            return null;
//        }
//
//    }
    /**
     * @return the id
     */
    public int getId() {
        return id;
    }

    /**
     * @param id the id to set
     */
    public void setId(int id) {
        this.id = id;
    }

    /**
     * @return the id
     */
    public int getFc5003() {
        return fc5003;
    }

    /**
     * @param id the id to set
     */
    public void setFc5003(int fc5003) {
        this.fc5003 = fc5003;
    }

    /**
     * @return the lastName
     */
    public String getLastName() {
        return lastName;
    }

    /**
     * @param lastName the lastName to set
     */
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    /**
     * @return the firstName
     */
    public String getFirstName() {
        return firstName;
    }

    /**
     * @param firstName the firstName to set
     */
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    /**
     * @return the userName
     */
    public String getUserName() {
        return userName;
    }

    /**
     * @param userName the userName to set
     */
    public void setUserName(String userName) {
        this.userName = userName;
    }

    /**
     * @return the password
     */
    public String getPassword() {
        return password;
    }

    /**
     * @param password the password to set
     */
    public void setPassword(String password) {
        this.password = password;
    }

    /**
     * @return the companyNo
     */
    public int getCompanyNo() {
        return companyNo;
    }

    /**
     * @param companyNo the companyNo to set
     */
    public void setCompanyNo(int companyNo) {
        this.companyNo = companyNo;
    }

    /**
     * @return the companyName
     */
    public String getCompanyName() {
        return companyName;
    }

    /**
     * @param companyName the companyName to set
     */
    public void setCompanyName(String companyName) {
        this.companyName = companyName;
    }

    /**
     * @return the departmentNo
     */
    public int getDepartmentNo() {
        return departmentNo;
    }

    /**
     * @param departmentNo the departmentNo to set
     */
    public void setDepartmentNo(int departmentNo) {
        this.departmentNo = departmentNo;
    }

    /**
     * @return the phongBan
     */
    public String getPhongBan() {
        return phongBan;
    }

    /**
     * @param phongBan the phongBan to set
     */
    public void setPhongBan(String phongBan) {
        this.phongBan = phongBan;
    }

    /**
     * @return the customer
     */
    public int getCustomer() {
        return customer;
    }

    /**
     * @param customer the customer to set
     */
    public void setCustomer(int customer) {
        this.customer = customer;
    }

    public static void main(String arg[]) throws Exception {
        Login login = new Login();
        login.checkLogin(9, "ntn", "61bd60c60d9fb60cc8fc7767669d40a1");
    }

    /**
     * @return the showGlobalMessage
     */
    public boolean isShowGlobalMessage() {
        return showGlobalMessage;
    }

    /**
     * @param showGlobalMessage the showGlobalMessage to set
     */
    public void setShowGlobalMessage(boolean showGlobalMessage) {
        this.showGlobalMessage = showGlobalMessage;
    }

    /**
     * @return the globalMessage
     */
    public String getGlobalMessage() {
        return globalMessage;
    }

    /**
     * @param globalMessage the globalMessage to set
     */
    public void setGlobalMessage(String globalMessage) {
        this.globalMessage = globalMessage;
    }

    /**
     * @return the showLocalMessage
     */
    public boolean isShowLocalMessage() {
        return showLocalMessage;
    }

    /**
     * @param showLocalMessage the showLocalMessage to set
     */
    public void setShowLocalMessage(boolean showLocalMessage) {
        this.showLocalMessage = showLocalMessage;
    }

    /**
     * @return the localMessage
     */
    public String getLocalMessage() {
        return localMessage;
    }

    /**
     * @param localMessage the localMessage to set
     */
    public void setLocalMessage(String localMessage) {
        this.localMessage = localMessage;
    }

    /**
     * @return the module
     */
    public int getModule() {
        return module;
    }

    /**
     * @param module the module to set
     */
    public void setModule(int module) {
        this.module = module;
    }

    /**
     * @return the ni104
     */
    public int getNi104() {
        return ni104;
    }

    /**
     * @param ni104 the ni104 to set
     */
    public void setNi104(int ni104) {
        this.ni104 = ni104;
    }

    /**
     * @return the val
     */
    public int getVal() {
        return val;
    }

    /**
     * @param val the val to set
     */
    public void setVal(int val) {
        this.val = val;
    }

    /**
     * @return the label
     */
    public String getLabel() {
        return label;
    }

    /**
     * @param label the label to set
     */
    public void setLabel(String label) {
        this.label = label;
    }

    /**
     * @return the qv115
     */
    public String getQv115() {
        if (qv115.equals("de")) {
            setQv115("Deutsch");
        }
        if (qv115.equals("en")) {
            setQv115("English");
        }

        return qv115;
    }

    /**
     * @param qv115 the qv115 to set
     */
    public void setQv115(String qv115) {
        this.qv115 = qv115;
    }

    /**
     * @return the status
     */
    public String getStatus() {
        return status;
    }

    /**
     * @param status the status to set
     */
    public void setStatus(String status) {
        this.status = status;
    }

    /**
     * @return the fullad
     */
    public int getFullad() {
        return fullad;
    }

    /**
     * @param fullad the fullad to set
     */
    public void setFullad(int fullad) {
        this.fullad = fullad;
    }

    /**
     * @return the character
     */
    public String getCharacter() {
        return character;
    }

    /**
     * @param character the character to set
     */
    public void setCharacter(String character) {
        this.character = character;
    }

    /**
     * @return the qv116
     */
    public String getQv116() {
        return qv116;
    }

    /**
     * @param qv116 the qv116 to set
     */
    public void setQv116(String qv116) {
        this.qv116 = qv116;
    }

    /**
     * @return the qv114
     */
    public String getQv114() {
        return qv114;
    }

    /**
     * @param qv114 the qv114 to set
     */
    public void setQv114(String qv114) {
        this.qv114 = qv114;
    }

    /**
     * @return the fn850
     */
    public int getFn850() {
        return fn850;
    }

    /**
     * @param fn850 the fn850 to set
     */
    public void setFn850(int fn850) {
        this.fn850 = fn850;
    }

    /**
     * @return the listN450
     */
    public List<N450> getListN450() {
        N450Store store = new N450Store();
        listN450 = store.findAllN450ForCombo(7, 99, getUserName());
        return listN450;
    }

    public void setListN450(List<N450> listN450) {
        this.listN450 = listN450;
    }

    /**
     * @return the listN850
     */
    public List<N850> getListN850() {
        return listN850;
    }

    /**
     * @param listN850 the listN850 to set
     */
    public void setListN850(List<N850> listN850) {
        this.listN850 = listN850;
    }

    /**
     * @return the nv451
     */
    public String getNv451() {
        return nv451;
    }

    public void setNv451(String nv451) {
        this.nv451 = nv451;
    }

    /**
     * @return the nv851
     */
    public String getNv851() {
        return nv851;
    }

    /**
     * @param nv851 the nv851 to set
     */
    public void setNv851(String nv851) {
        this.nv851 = nv851;
    }

    /**
     * @return the nv251
     */
    public String getNv251() {
        return nv251;
    }

    public void setNv251(String nv251) {
        this.nv251 = nv251;
    }

    /**
     * @return the nv115
     */
    public String getNv115() {
        return nv115;
    }

    /**
     * @param nv115 the nv115 to set
     */
    public void setNv115(String nv115) {
        this.nv115 = nv115;
    }

    /**
     * @return the sex
     */
    public String getSex() {
        try {
            if (nv115.equals("M")) {
                sex = "Nam";
            } else {
                sex = "Nữ";
            }
        } catch (Exception e) {
        }
        return sex;
    }

    /**
     * @param sex the sex to set
     */
    public void setSex(String sex) {
        this.sex = sex;
    }

    /**
     * @return the fn450
     */
    public int getFn450() {
        return fn450;
    }

    /**
     * @param fn450 the fn450 to set
     */
    public void setFn450(int fn450) {
        this.fn450 = fn450;
    }

    /**
     * @return the fk100
     */
    public int getFk100() {
        return fk100;
    }

    /**
     * @param fk100 the fk100 to set
     */
    public void setFk100(int fk100) {
        this.fk100 = fk100;
    }

    /**
     * @return the hoten
     */
    public String getHoten() {
        return hoten;
    }

    /**
     * @param hoten the hoten to set
     */
    public void setHoten(String hoten) {
        this.hoten = hoten;
    }

    /**
     * @return the qv117
     */
    public String getQv117() {
        return qv117;
    }

    public void setQv117(String qv117) {
        this.qv117 = qv117;
    }

    /**
     * @return the qv118
     */
    public String getQv118() {
        return qv118;
    }

    public void setQv118(String qv118) {
        this.qv118 = qv118;
    }

    /**
     * @return the qv119
     */
    public String getQv119() {
        return qv119;
    }

    public void setQv119(String qv119) {
        this.qv119 = qv119;
    }

    /**
     * @return the qv120
     */
    public String getQv120() {
        return qv120;
    }

    public void setQv120(String qv120) {
        this.qv120 = qv120;
    }

    /**
     * @return the qv121
     */
    public String getQv121() {
        return qv121;
    }

    public void setQv121(String qv121) {
        this.qv121 = qv121;
    }
}
